package com.xbx.baseweb.controller;

import com.xbx.baseweb.constant.ResponseCode;
import com.xbx.baseweb.model.ResponseModel;

import java.util.HashMap;
import java.util.Map;

/**
 * 89005691
 */
public class ResultUtils {

    public static ResponseModel fail(int code, String msg) {
        ResponseModel result = new ResponseModel();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static ResponseModel success(String msg) {
        ResponseModel result = new ResponseModel();
        result.setCode(ResponseCode.SUCCESS.getCode());
        result.setMsg(msg);
        return result;
    }

    public static ResponseModel success(String key, Object value) {
        ResponseModel result = new ResponseModel();
        result.setCode(ResponseCode.SUCCESS.getCode());
        result.setMsg("success");
        Map<String, Object> model = new HashMap<>(1);
        model.put(key, value);
        result.setData(model);
        return result;
    }

    public static ResponseModel success(String msg, String key, Object value) {
        ResponseModel result = new ResponseModel();
        result.setCode(ResponseCode.SUCCESS.getCode());
        result.setMsg(msg);
        Map<String, Object> model = new HashMap<>(1);
        model.put(key, value);
        result.setData(model);
        return result;
    }

}
